package com.guigu.springcloud.controller;

import com.guigu.springcloud.common.CommonResult;
import com.guigu.springcloud.entity.Payment;
import com.guigu.springcloud.service.PaymentService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

@RestController
@RequestMapping("/payment/zk")
@Slf4j
public class PaymentController {

    @Resource
    private PaymentService paymentService;

    @Value("${server.port}")
    private String serverPort;

    @PostMapping
    public CommonResult create(@RequestBody Payment payment) {
        log.info(payment.toString());
        int result = paymentService.create(payment);
        return CommonResult.voData(200, "创建成功" + serverPort, result);
    }

    @GetMapping(value = "/{id}")
    public CommonResult findById(@PathVariable("id") Long id) {
        log.info(id.toString());
        Payment payment = paymentService.findById(id);
        log.info(payment.toString());
        return CommonResult.voData(200, "查询成功" + serverPort, payment);
    }
}
